package com.fanghuaiming;

import com.fanghuaiming.entity.Student;
import com.fanghuaiming.service.UserService;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.api.KieServices.Factory;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

/****
 * @description:
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2021/6/13 下午10:41
 *
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class testgetWorkingMemory {

    @Autowired
    private UserService userService;

  @Test
  public void test1() {
    // 设置日期格式
    System.setProperty("drools.dateformat", "yyyy-MM-dd HH:mm");
    KieSession kieSession = Factory.get().getKieClasspathContainer().newKieSession();
    // 因为其他规则的原因需要添加以下废代码
    kieSession.setGlobal("userService", userService);
    kieSession.setGlobal("count", 5);
    List<Object> globalList = new ArrayList<>();
    kieSession.setGlobal("globalList", globalList);
    // 因为其他规则的原因需要添加以上废代码

      Student student = new Student();
      student.setName("张三");

      kieSession.insert(student);
      kieSession.fireAllRules();
      kieSession.dispose();
  }

}
